package com.shujia.Dao;

import com.shujia.JdbcUtil.JdbcUitl;
import com.shujia.JdbcUtil.JdbcUtil_plus;
import com.shujia.user.Student;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class StuentDao {

    public Student QueryStudentById(String id){
        Student student = null;
        Connection conn = null;
        try {
            conn = JdbcUtil_plus.getConnection();
            PreparedStatement ps = conn.prepareStatement("select * from student where id=?");
            ps.setString(1,id);
            ResultSet rs = ps.executeQuery();
            while (rs.next()){

                student = new Student();

                String name = rs.getString("name");
                int age = rs.getInt("age");
                String gender = rs.getString("gender");
                String clazz = rs.getString("clazz");

               student.setId(id);
               student.setName(name);
               student.setAge(age);
               student.setGender(gender);
               student.setClazz(clazz);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return student;
    }
}
